$(function() {
	if(getCookieValue("token")==""){
		window.location.href = 'l-userlogin.html'
	}
	
	
	var vLink;
	var vPage;
	var vStore;
	$('.btn2').on('tap', function() {
		if($('.v-link').hasClass('mui-active')) {
			vLink = 1;
		} else {
			vLink = 0;
		}
		if($('.v-page').hasClass('mui-active')) {
			vPage = 1;
		} else {
			vPage = 0;
		}
		if($('.v-store').hasClass('mui-active')) {
			vStore = 1;
		} else {
			vStore = 0;
		}
		console.log(vLink);
		console.log(vPage);
		console.log(vStore);
		if(vLink==0 && vPage==0 && vStore==0){
			mui.toast('还有没选择！');
			return false;
		};
		mirrorTo({
			token: getCookieValue("token"),
			microSinglePageIs: vPage,
			microShopIs: vStore,
			microlinkIs: vLink,
			isSynchronize: 1
		}, function(data) {
			console.log(data);
			if(data.code == 200) {
				mui.toast('同步成功')
			}
		})
	});
	$('.btn1').on('tap', function() {
		mui.confirm('确定解除镜像关系吗？', '提示', function(e) {
			if(e.index == 1) {
				if($('.v-link').hasClass('mui-active')) {
					vLink = 1;
				} else {
					vLink = 0;
				}
				if($('.v-page').hasClass('mui-active')) {
					vPage = 1;
				} else {
					vPage = 0;
				}
				if($('.v-store').hasClass('mui-active')) {
					vStore = 1;
				} else {
					vStore = 0;
				};
				if(vLink==0 && vPage==0 && vStore==0){
			mui.toast('还有没选择！');
			return false;
		};
				mirrorTo({
					token: getCookieValue("token"),
					microSinglePageIs: vPage,
					microShopIs: vStore,
					microlinkIs: vLink,
					isSynchronize: 0
				}, function(data) {
					console.log(data);
					if(data.code == 200) {
						mui.toast('解除成功')
					}
				})
			}
		})
	});

	mirrorUserTo({
		c_user_id: CD.geturl().business
	}, function(data) {
		console.log(data.data.user_img)
		$('.user-header > img').attr({
			"src":data.data.user_img
		});
		$('.user-header > span').html(data.data.user_name);
		$('.mirror-people').on('tap',function(){
			window.location.href = "u-home.html?business="+data.data.user_uuid;
		});
	})

})
//镜像同步
var mirrorTo = function(params, callback) {
	$.ajax({
		type: "post",
		url: window.address + "/user/mirrorOperate",
		data: params,
		dataType: "json",
		success: function(data) {
			callback && callback(data)
		}
	});
}

var mirrorUserTo = function(params, callback) {
	$.ajax({
		type: "get",
		url: window.address + "/user/getSuperUser",
		data: params,
		dataType: "json",
		success: function(data) {
			console.log(data,8888)
			callback && callback(data)
		}
	});
}